//导入 jsonwebtoken
const jwt = require('jsonwebtoken');
let secret = 'ajfieowahfeiopwhfuipewahfeiwpahjfeiwoapfjewuioa';
//创建一个 token
let token = jwt.sign({
  name: 'zhangsan',
  user_id: 20
}, secret, {
  expiresIn: 3
}); // sign

setTimeout(() => {
  //校验 token 提取 token 中的用户信息
  jwt.verify(token, secret, (err, data) => {
    if(err) throw err;
    console.log(data);
  });
}, 2000);